﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Catering_DBOpertion;
using System.Data.SqlClient;
using System.Data;

namespace Catering_Operation
{
    public partial class DailyCaiGouInfo
    {

        public DailyCaiGouInfo()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
            return DbHelperSQL.GetMaxID("id", "DailyCaiGouInfo"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select count(1) from DailyCaiGouInfo");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
        public void Add(Catering_Model.DailyCaiGouInfo model)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("insert into DailyCaiGouInfo(");
            strSql.Append("[DailyManagementID],[GroupID],[ClassID],[AccessName],[ModelRuler],[AccessUnit],[AccessNumber],[ConDesc])");
			strSql.Append(" values (");
            strSql.Append("@DailyManagementID,@GroupID,@ClassID,@AccessName,@ModelRuler,@AccessUnit,@AccessNumber,@ConDesc)");
            SqlParameter[] parameters = {
					new SqlParameter("@DailyManagementID", SqlDbType.Int,4),
					new SqlParameter("@GroupID", SqlDbType.VarChar,50),
					new SqlParameter("@ClassID", SqlDbType.VarChar,50),
                    new SqlParameter("@AccessName", SqlDbType.VarChar,50),
					new SqlParameter("@ModelRuler", SqlDbType.VarChar,50),
					new SqlParameter("@AccessUnit", SqlDbType.VarChar,50),
					new SqlParameter("@AccessNumber", SqlDbType.Decimal,10),
					new SqlParameter("@ConDesc", SqlDbType.Text,0)};
            parameters[0].Value = model.DailyManagementID;
            parameters[1].Value = model.GroupID;
            parameters[2].Value = model.ClassID;
            parameters[3].Value = model.AccessName;
            parameters[4].Value = model.ModelRuler;
            parameters[5].Value = model.AccessUnit;
            parameters[6].Value = model.AccessNumber;
            parameters[7].Value = model.ConDesc;
			DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
        public bool Update(Catering_Model.DailyCaiGouInfo model)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("update DailyCaiGouInfo set ");
            strSql.Append("DailyManagementID=@DailyManagementID,");
			strSql.Append("GroupID=@GroupID,");
            strSql.Append("ClassID=@ClassID,");
            strSql.Append("AccessName=@AccessName,");
            strSql.Append("ModelRuler=@ModelRuler,");
            strSql.Append("AccessUnit=@AccessUnit,");
            strSql.Append("AccessNumber=@AccessNumber,");
            strSql.Append("ConDesc=@ConDesc,");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@DailyManagementID", SqlDbType.Int,4),
					new SqlParameter("@GroupID", SqlDbType.VarChar,50),
                    new SqlParameter("@ClassID", SqlDbType.VarChar,50),
					new SqlParameter("@AccessName", SqlDbType.VarChar,50),
					new SqlParameter("@ModelRuler", SqlDbType.VarChar,50),
					new SqlParameter("@AccessUnit", SqlDbType.VarChar,50),
					new SqlParameter("@AccessNumber", SqlDbType.Decimal,10),
					new SqlParameter("@ConDesc", SqlDbType.Text,0),
                    new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = model.DailyManagementID;
			parameters[1].Value = model.GroupID;
            parameters[2].Value = model.ClassID;
            parameters[3].Value = model.AccessName;
            parameters[4].Value = model.ModelRuler;
            parameters[5].Value = model.AccessUnit;
            parameters[6].Value = model.AccessNumber;
            parameters[7].Value = model.ConDesc;
			parameters[8].Value = model.id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
            strSql.Append("delete from DailyCaiGouInfo ");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("delete from DailyCaiGouInfo ");
            strSql.Append(" where " + idlist);
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public Catering_Model.DailyCaiGouInfo GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 id,DailyManagementID,GroupID,ClassID,AccessName,ModelRuler,AccessUnit,AccessNumber,ConDesc from DailyCaiGouInfo ");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = id;

            Catering_Model.DailyCaiGouInfo model = new Catering_Model.DailyCaiGouInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["id"]!=null && ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
                if (ds.Tables[0].Rows[0]["DailyManagementID"] != null && ds.Tables[0].Rows[0]["DailyManagementID"].ToString() != "")
				{
                    model.DailyManagementID = int.Parse(ds.Tables[0].Rows[0]["DailyManagementID"].ToString());
				}				
				if(ds.Tables[0].Rows[0]["GroupID"]!=null && ds.Tables[0].Rows[0]["GroupID"].ToString()!="")
				{
					model.GroupID=ds.Tables[0].Rows[0]["GroupID"].ToString();
				}
                if (ds.Tables[0].Rows[0]["ClassID"] != null && ds.Tables[0].Rows[0]["ClassID"].ToString() != "")
                {
                    model.ClassID = ds.Tables[0].Rows[0]["ClassID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["AccessName"] != null && ds.Tables[0].Rows[0]["AccessName"].ToString() != "")
				{
                    model.AccessName = ds.Tables[0].Rows[0]["AccessName"].ToString();
				}
                if (ds.Tables[0].Rows[0]["ModelRuler"] != null && ds.Tables[0].Rows[0]["ModelRuler"].ToString() != "")
				{
                    model.ModelRuler = ds.Tables[0].Rows[0]["ModelRuler"].ToString();
				}
                if (ds.Tables[0].Rows[0]["AccessUnit"] != null && ds.Tables[0].Rows[0]["AccessUnit"].ToString() != "")
				{
                    model.AccessUnit = ds.Tables[0].Rows[0]["AccessUnit"].ToString();
				}
                if (ds.Tables[0].Rows[0]["AccessNumber"] != null && ds.Tables[0].Rows[0]["AccessNumber"].ToString() != "")
				{
                    model.AccessNumber =Convert.ToDecimal(ds.Tables[0].Rows[0]["AccessNumber"].ToString());
				}
                if (ds.Tables[0].Rows[0]["ConDesc"] != null && ds.Tables[0].Rows[0]["ConDesc"].ToString() != "")
				{
                    model.ConDesc = ds.Tables[0].Rows[0]["ConDesc"].ToString();
				}                
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select [ID],[CID],[CName],[GroupID],[ClassID],[CardNo],[JobCard],[Effective],[Tel],[ConDesc],[OldClassID],[OldGroupID],[ChangeClassDate] ");
            strSql.Append(" FROM DailyCaiGouInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
            strSql.Append(" [ID],[CID],[CName],[GroupID],[ClassID],[CardNo],[JobCard],[Effective],[Tel],[ConDesc],[OldClassID],[OldGroupID],[ChangeClassDate] ");
            strSql.Append(" FROM DailyCaiGouInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
            parameters[0].Value = "DailyCaiGouInfo";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;
            return DbHelperSQL.RunProcedure("GetPageData", parameters, "DailyCaiGouInfo");
		}

        /// <summary>
        /// 根据条件获取数据总条数
        /// </summary>
        public int GetCountBywhere(string where)
        {
            string strSql = string.Format("select count(*) from DailyCaiGouInfo where {0}", where);
            return Convert.ToInt32(DbHelperSQL.GetSingle(strSql));
        }

		#endregion  Method

    }
}
